<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<script type="text/javascript">

    function studentDelete(studentId) {
        if(confirm("您确定要删除这个学生吗？")) {
            location.href="${pageContext.request.contextPath}/student/removeStudent?id="+studentId;
        }
    }

    function checkForm(){
        var didSelect = $("#conditions").val();
        var vs = $("#conditions").find("option:selected").text();
        console.log(didSelect+"-"+vs);
        return true;
    }

    function popupDorm(){
        var vs = $("#conditions").val();
        if(vs === "buildingname"){
            htmlcontext = '寝室号  <input id="number" name="number" value="" type="text"  style="width:120px;height: 30px;" class="input-medium search-query">';
            $("#number").html(htmlcontext);
        }else{
            $("#number").html("");
        }
    }
</script>

<style type="text/css">
    .span6 {
        width:0px;
        height: 0px;
        padding-top: 0px;
        padding-bottom: 0px;
        margin-top: 0px;
        margin-bottom: 0px;
    }

</style>
<div class="data_list">
    <div class="data_list_title" style="text-align: center; font-size: 35px">
        学生管理
    </div>
    <form class="form-search" method="post" action="${pageContext.request.contextPath}/student/findAll" style="padding-bottom: 0px" onsubmit="return checkForm()">
        <button class="btn btn-primary" type="button" style="margin-right: 50px;" onclick="location.href='${pageContext.request.contextPath}/student/addStudent?para=add'">添加</button>
        <span class="data_search">
            <span id = "number"></span>
                <select id="conditions" name="conditions" onchange="popupDorm()" style="width: 110px;">
                    <option value="stuCode">学号</option>
                    <option value="name">姓名</option>
                    <option value="grade">班级</option>
                    <option value="buildingname">楼号</option>
                </select>
            &nbsp;<input id="information" name="information" value="" type="text"  style="width:120px;height: 30px;" class="input-medium search-query">
            &nbsp;<button type="submit" class="btn btn-info">搜索</button>
        </span>
    </form>
    <div>
        <table class="table table-striped table-bordered table-hover datatable">
            <thead>
            <tr>
                <th>学号</th>
                <th>姓名</th>
                <th>性别</th>
                <th>电话</th>
                <th>班级</th>
                <th>宿舍楼</th>
                <th>寝室号</th>
            </tr>
            </thead>
            <tbody>
            <c:forEach items="${students}" var="student">
                <tr>
                    <td>${student.stuCode}</td>
                    <td>${student.name}</td>
                    <td>${student.grade}</td>
                    <td>${student.sex}</td>
                    <td>${student.phone}</td>
                    <td>${student.building.name}</td>
                    <td>${student.dormitory.number}</td>
                    <td>
                        <button class="btn btn-primary" type="button" onclick="location.href='${pageContext.request.contextPath}/record/findAll?conditions=sid&information=${student.id}'">查看出勤记录</button>
                        <button class="btn btn-primary" type="button" onclick="location.href='${pageContext.request.contextPath}/student/findOneStudent?id=${student.id}'">修改</button>&nbsp;
                        <button class="btn btn-primary" type="button" onclick="studentDelete(${student.id})">删除</button>
                    </td>
                </tr>
            </c:forEach>

            </tbody>
        </table>
    </div>
    <div align="center"><font color="red"></font></div>
</div>
